<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!doctype html>
<html>
    <head>
        <c:import url="html_head.jsp" />
        <title>Evidence příjmů a výdajů</title>
    </head>
    <body>
        <c:import url="page_head.jsp" />
        <div class="container">
            <div class="body">
                <p id="old-browser" class="message warning hidden">Používáte zastaralý internetový prohlížeč, a některé funkce této aplikace mohou proto být nepřístupné. Aktualizujte prosím svůj internetový prohlížeč.</p>

                <div class="box" id="filter">
                    <form method="get" action="filter" id="frm-filter">
                        <div>
                            <label for="frm-filter-subject">Subjekt</label>
                            <select id="frm-filter-subject" name="subject">
                                <option value="">Žádný</option>
                                <c:forEach items="${subjects}" var="subject">
                                    <option value="${subject.value.id}"<c:if test="${subject.value == filterSubject}"> selected="selected"</c:if>><c:out value="${subject.value.name}"/></option>
                                </c:forEach>
                            </select>
                        </div>

                        <div>
                            <label for="frm-filter-from">Od</label>
                            <input type="date" id="frm-filter-from" name="from" value="<c:if test="${filterDateFrom != null}"><fmt:formatDate value="${filterDateFrom.time}" type="date" pattern="yyyy-MM-dd" /></c:if>" />
                        </div>

                        <div>
                            <label for="frm-filter-to">Do</label>
                            <input type="date" id="frm-filter-to" name="to" value="<c:if test="${filterDateTo != null}"><fmt:formatDate value="${filterDateTo.time}" type="date" pattern="yyyy-MM-dd" /></c:if>" />
                        </div>

                        <div>
                            <a href="#" id="frm-filter-clear">Smazat hodnoty</a>
                            <input type="submit" name="send" value="Filtrovat" />
                        </div>
                    </form>
                </div>
                <c:import url="notifications.jsp" />
                <form action="save" method="post">
                    <table>
                        <thead>
                            <tr>
                                <th class="w15">ID</th>
                                <th class="w10">Datum</th>
                                <th class="w15">Subjekt</th>
                                <th class="w30">Účel platby</th>
                                <th class="w13 num">Částka</th>
                                <th class="w7 icons"></th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr id="row-add">
                                <td colspan="6" class="center add">
                                    <a href="#" id="btn-add" class="full">Přidat položku</a>
                                </td>
                            </tr>
                            <tr id="frm-add" class="hidden">
                                <td>
                                    <input type="text" id="frm-add-number" name="number[new]" data-required="true" />
                                </td>
                                <td>
                                    <jsp:useBean id="now" class="java.util.Date" />
                                    <input type="date" id="frm-add-date" name="date[new]" value="<fmt:formatDate value="${now}" type="date" pattern="yyyy-MM-dd" />" data-required="true" />
                                </td>
                                <td>
                                    <select id="frm-add-subject" name="subject[new]">
                                        <c:forEach items="${subjects}" var="subject">
                                            <option value="${subject.value.id}"><c:out value="${subject.value.name}"/></option>
                                        </c:forEach>
                                    </select>
                                </td>
                                <td>
                                    <input type="text" id="frm-add-description" name="description[new]" />
                                </td>
                                <td class="num">
                                    <input type="number" id="frm-add-amount" name="amount[new]"  data-required="true" />
                                </td>
                                <td class="icons center">
                                    <input type="image" name="send[new]" class="icon icon-add" title="Uložit" alt="Uložit" />
                                </td>
                            </tr>
                            <c:forEach items="${payments}" var="payment">
                                <tr class="item" id="item-${payment.id}" data-id="${payment.id}">
                                    <td><c:out value="${payment.number}" /></td>
                                    <td><fmt:formatDate value="${payment.date.time}" type="date" dateStyle="short" /></td>
                                    <td><c:out value="${subjects[payment.subjectID].name}" /></td>
                                    <td><c:out value="${payment.description}" /></td>
                                    <td class="num<c:if test="${payment.amount.unscaledValue() < 0}"> minus</c:if>"><c:out value="${payment.amount}" /></td>
                                    <td class="icons center">
                                        <a href="#" class="icon icon-edit" title="Upravit"></a>
                                        <a href="delete?payment=${payment.id}" class="icon icon-del confirm" data-confirm="Opravdu chcete smazat tento záznam?" title="Smazat"></a>
                                    </td>
                                </tr>
                                <tr class="hidden frm-edit" id="frm-edit-${payment.id}" data-id="${payment.id}">
                                    <td>
                                        <input type="hidden" id="frm-edit-${payment.id}-id" name="id[${payment.id}]" value="${payment.id}" />
                                        <input type="text" id="frm-edit-${payment.id}-number" name="number[${payment.id}]" value="${payment.number}" data-required="true" />
                                    </td>
                                    <td>
                                        <input type="date" id="frm-edit-${payment.id}-date" name="date[${payment.id}]" value="<fmt:formatDate value="${payment.date.time}" type="date" pattern="yyyy-MM-dd" />"  data-required="true" />
                                    </td>
                                    <td>
                                        <select id="frm-edit-${payment.id}-subject" name="subject[${payment.id}]">
                                        <c:forEach items="${subjects}" var="subject">
                                            <option value="${subject.value.id}"<c:if test="${payment.subjectID == subject.value.id}"> selected="selected"</c:if>><c:out value="${subject.value.name}"/></option>
                                        </c:forEach>
                                        </select>
                                    </td>
                                    <td>
                                        <input type="text" id="frm-edit-${payment.id}-description" name="description[${payment.id}]" value="${payment.description}" />
                                    </td>
                                    <td class="num">
                                        <input type="number" id="frm-edit-${payment.id}-amount" name="amount[${payment.id}]" value="${payment.amount}"  data-required="true" />
                                    </td>
                                    <td class="icons center">
                                        <input type="image" name="send[${payment.id}]" class="icon icon-add" title="Uložit" alt="Uložit" />
                                        <a href="#" class="icon icon-cancel" title="Storno"></a>
                                    </td>
                                </tr>
                            </c:forEach>
                            <tr>
                                <td colspan="4">Příjmy celkem</td>
                                <td class="num"><c:out value="${income}" /></td>
                                <td class="icons"></td>
                            </tr>
                            <tr>
                                <td colspan="4">Výdaje celkem</td>
                                <td class="num minus"><c:out value="${expenses}" /></td>
                                <td class="icons"></td>
                            </tr>
                            <tr>
                                <td class="b" colspan="4">SOUČET</td>
                                <td class="num<c:if test="${balance < 0}"> minus</c:if>"><c:out value="${balance}" /></td>
                                <td class="icons"></td>
                            </tr>
                        </tbody>
                    </table>
                </form>

                <div class="box right">
                    <div class="btn-group">
                        <a class="btn" href="#" id="btn-print">Tisknout</a><!--
                        --><a class="btn" href="./export">Export Docbook</a><a class="btn" href="./exportpdf">Export PDF</a>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>